/*     */ package com.zimbra.cs.service;
/*     */ 
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraCookie;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AuthToken;
/*     */ import com.zimbra.cs.account.AuthTokenException;
/*     */ import com.zimbra.cs.account.ZimbraAuthToken;
/*     */ import com.zimbra.cs.account.auth.AuthMechanism.AuthMech;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.Cookie;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ZimbraAuthProvider
/*     */   extends AuthProvider
/*     */ {
/*     */   public static final String ZIMBRA_AUTH_PROVIDER = "zimbra";
/*     */   
/*     */   ZimbraAuthProvider()
/*     */   {
/*  40 */     this("zimbra");
/*     */   }
/*     */   
/*     */   protected ZimbraAuthProvider(String name) {
/*  44 */     super(name);
/*     */   }
/*     */   
/*     */   private String getEncodedAuthTokenFromCookie(HttpServletRequest req, boolean isAdminReq) {
/*  48 */     String cookieName = ZimbraCookie.authTokenCookieName(isAdminReq);
/*  49 */     String encodedAuthToken = null;
/*  50 */     Cookie[] cookies = req.getCookies();
/*  51 */     if (cookies != null) {
/*  52 */       for (int i = 0; i < cookies.length; i++) {
/*  53 */         if (cookies[i].getName().equals(cookieName)) {
/*  54 */           encodedAuthToken = cookies[i].getValue();
/*  55 */           break;
/*     */         }
/*     */       }
/*     */     }
/*  59 */     return encodedAuthToken;
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(HttpServletRequest req, boolean isAdminReq)
/*     */     throws AuthProviderException, AuthTokenException
/*     */   {
/*  65 */     String encodedAuthToken = getEncodedAuthTokenFromCookie(req, isAdminReq);
/*  66 */     return genAuthToken(encodedAuthToken);
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(Element soapCtxt, Map engineCtxt)
/*     */     throws AuthProviderException, AuthTokenException
/*     */   {
/*  72 */     String encodedAuthToken = soapCtxt == null ? null : soapCtxt.getAttribute("authToken", null);
/*     */     
/*     */ 
/*     */ 
/*  76 */     if (encodedAuthToken == null) {
/*  77 */       encodedAuthToken = (String)engineCtxt.get("zimbra.authToken");
/*     */     }
/*     */     
/*     */ 
/*  81 */     if (encodedAuthToken == null) {
/*  82 */       HttpServletRequest req = (HttpServletRequest)engineCtxt.get("servlet.request");
/*  83 */       if (req != null) {
/*  84 */         Boolean isAdminReq = (Boolean)engineCtxt.get("zimbra.isadminreq");
/*  85 */         if (isAdminReq != null)
/*     */         {
/*  87 */           encodedAuthToken = getEncodedAuthTokenFromCookie(req, isAdminReq.booleanValue());
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*  92 */     return genAuthToken(encodedAuthToken);
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(String encoded) throws AuthProviderException, AuthTokenException
/*     */   {
/*  97 */     return genAuthToken(encoded);
/*     */   }
/*     */   
/*     */   protected AuthToken genAuthToken(String encodedAuthToken) throws AuthProviderException, AuthTokenException {
/* 101 */     if (StringUtil.isNullOrEmpty(encodedAuthToken)) {
/* 102 */       throw AuthProviderException.NO_AUTH_DATA();
/*     */     }
/*     */     
/* 105 */     return ZimbraAuthToken.getAuthToken(encodedAuthToken);
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(Account acct)
/*     */   {
/* 110 */     return new ZimbraAuthToken(acct);
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(Account acct, boolean isAdmin, AuthMechanism.AuthMech authMech)
/*     */   {
/* 115 */     return new ZimbraAuthToken(acct, isAdmin, authMech);
/*     */   }
/*     */   
/*     */   protected AuthToken authToken(Account acct, long expires)
/*     */   {
/* 120 */     return new ZimbraAuthToken(acct, expires);
/*     */   }
/*     */   
/*     */ 
/*     */   protected AuthToken authToken(Account acct, long expires, boolean isAdmin, Account adminAcct)
/*     */   {
/* 126 */     return new ZimbraAuthToken(acct, expires, isAdmin, adminAcct, null);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/ZimbraAuthProvider.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */